import download from "download-git-repo";
import ora from "ora";

const downloadFun = async function (url, project) {
	return new Promise((resolve, reject) => {
		const spinner = ora({ color: "yellow" }).start();
		spinner.text = "代码正在下载……";
		download(`direct:${url}`, project, { clone: true }, (err) => {
			if (err) {
				spinner.fail("代码下载失败");
				reject(err);
				return;
			}
			spinner.succeed("代码下载成功");
			resolve(true);
		});
	});
};

export default downloadFun;
